/*
 * 文件名               :  SocketHandlerFinder.java
 * 用途                    :  持有特定Id的SocketHandler,全部方法都是线程安全的
 * 最后修改日期:  $LastChangedDate: 2009-09-14 13:13:18 +0000 (Mon, 14 Sep 2009) $
 * 最后修改者     :  $LastChangedBy: wendal1985@gmail.com $
 * 创建者               :  Wendal Chen <wendal1985@gmail.com>
 */
package com.wendal.java.preproxy.server;

import java.util.HashMap;
import java.util.Map;

import com.wendal.java.preproxy.thread.SocketHandler;

public class SocketHandlerFinder {
	private Map<String, SocketHandler> map = new HashMap<String, SocketHandler>();

	public void addObject(String key,
			SocketHandler socketHandler) {
		if (key == null || socketHandler == null)
			return;
		synchronized (map) {
			if (map.get(key) != null) {
				System.out.println("Key =" + key + " 已经绑定一个对象");
			}
			map.put(key, socketHandler);
		}
	}

	public void remove(String key) {
		synchronized (map) {
			map.remove(key);
		}
	}

	public SocketHandler get(String key) {
		synchronized (map) {
			return map.get(key);
		}
	}
}
